package com.ado.bazinga.core.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ado.bazinga.core.dal.entity.Role;
import com.ado.bazinga.core.manager.RoleManager;
import com.ado.bazinga.core.service.RoleService;

/**
 *@author adonais
 *@date 2020年4月5日
 *@description RoleServiceImpl.java
**/
@Service(value = "roleService")
public class RoleServiceImpl implements RoleService {
	
	@Autowired
	@Qualifier(value = "roleManager")
	private RoleManager roleManager ;

	@Override
	public Role findByRoleId(String roleId) {
		Role role = new Role() ;
		if (StringUtils.isNotEmpty(roleId)) {
			role = roleManager.getById(Integer.valueOf(roleId));
		}
		return role;
	}

	@Override
	@Transactional
	public boolean createRole(Role role) {
		boolean flag = roleManager.saveOrUpdate(role) ;
		return flag;
	}

	@Override
	@Transactional
	public boolean deleteRole(String roleId) {
		boolean flag = roleManager.removeById(Integer.valueOf(roleId)) ;
		return flag;
	}

	@Override
	@Transactional
	public boolean updateRole(Role role) {
		boolean flag = roleManager.updateById(role) ;
		return flag;
	}

	@Override
	public List<Role> getAllRoles() {
		List<Role> roles = roleManager.list() ;
		return roles;
	}

}
